import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';

import format from '@dfeidao/atom-web/dt/format';
import render from '@dfeidao/atom-web/render/render';
import p007 from './p007';
/** 商务排序 */
export default async function a021(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	const i = e.currentTarget as HTMLElement;
	const datav = i.getAttribute('data-v');
	const datano = i.getAttribute('data-no');

	if (datano === "0") {
		const res = await nodejs<{ da3: Array<{ create_time: number }> }>('knowledge-base/zj-000001/s010', {
			filter: {
				data_v: datav
			}
		});
		const da3 = res.da3.map((n) => {
			return { ...n, create_time: format(n.create_time, 2) };
		});

		render(fd, da3, p007, 'p007', 'inner');
		i.setAttribute('data-no', '1');
	}
	if (datano === "1") {
		const res = await nodejs<{ dc3: Array<{ create_time: number }> }>('knowledge-base/zj-000001/s010', {
			filter: {
				data_v: datav
			}
		});
		const dc2 = res.dc3.map((n) => {
			return { ...n, create_time: format(n.create_time, 2) };
		});

		render(fd, dc2, p007, 'p007', 'inner');
		i.setAttribute('data-no', '0');
	}
}
